package com.example.venue_reservation_service.controller;

import com.example.venue_reservation_service.dto.AdminSlot;
import com.example.venue_reservation_service.dto.PointDTO;
import com.example.venue_reservation_service.service.AdminService;
import com.example.venue_reservation_service.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@CrossOrigin
@Tag(name = "管理员接口", description = "管理员及超级管理员专用接口，包含场馆管理、用户管理等操作")
public class AdminController {

    @Resource
    private AdminService adminService;

    @Operation(summary = "查询管理的场馆", description = "根据管理员ID查询其管理的所有场馆信息", parameters = {@Parameter(name = "userId", description = "管理员用户ID", required = true)})
    @GetMapping("/query")
    public Result query(@RequestParam("userId") Integer userId) {
        return adminService.queryVenue(userId);
    }

    @Operation(summary = "添加场地禁用时间", description = "设置指定场地的禁用时间段，用于维护或特殊安排", parameters = {@Parameter(name = "slot", description = "场地禁用时间对象，包含场地ID、开始/结束时间等信息", required = true)})
    @PostMapping("/time")
    public Result time(@RequestBody AdminSlot slot) {
        return adminService.addTime(slot);
    }

    @Operation(summary = "通过手机号查询用户", description = "根据手机号精确查询用户信息", parameters = {@Parameter(name = "phone", description = "用户手机号（11位数字）", required = true)})
    @GetMapping("/select")
    public Result select(@RequestParam("phone") String phone) {
        return adminService.selectUser(phone);
    }

    @Operation(summary = "为用户充值积分", description = "管理员为指定用户账号充值积分，支持备注说明", parameters = {@Parameter(name = "dto", description = "积分充值对象，包含用户ID、积分数量、操作备注等信息", required = true)})
    @PostMapping("/point")
    public Result point(@RequestBody PointDTO dto) {
        return adminService.userPoint(dto);
    }

    @Operation(summary = "管理员绑定关联场馆", description = "将管理员与指定类型的场馆进行关联，使其可以管理该场馆", parameters = {
                    @Parameter(name = "userId", description = "管理员用户ID", required = true),
                    @Parameter(name = "typeId", description = "场馆编号", required = true)})
    @PostMapping("/manage")
    public Result manage(@RequestParam("userId") Integer userId, @RequestParam("typeId") Integer typeId) {
        return adminService.manage(userId, typeId);
    }

    @Operation(summary = "移除关联场馆", description = "取消管理员与指定类型场馆的关联关系",
            parameters = {
                    @Parameter(name = "userId", description = "管理员用户ID", required = true),
                    @Parameter(name = "typeId", description = "场馆编号", required = true)})
    @PostMapping("/cancel")
    public Result cancel(@RequestParam("userId") Integer userId, @RequestParam("typeId") Integer typeId) {
        return adminService.cancel(userId, typeId);
    }
}